package com.hatch.utils 
{
	import flash.errors.*;
	import flash.events.*;
	import flash.system.*;
	import flash.text.*;	

	public class FontManager extends EventDispatcher
	{
		private static var INSTANCE:FontManager;
		private var _fontsDomain:ApplicationDomain;

		//private var _styleSheet:StyleSheet;
		public function FontManager(enforcer:SingletonEnforcer)
		{
			super();	
		}

		public function initialize(fontsDomain:ApplicationDomain):void 
		{
			
			if (_fontsDomain == null) 
			{
				_fontsDomain = fontsDomain;
				//_styleSheet = styles;
			} else {
				throw new IllegalOperationError("FontManager already initialized!");
			}
		}

		public function registerFonts(fontList:Array):void 
		{
			for (var i:uint = 0;i < fontList.length; i++) 
			{
				Font.registerFont(getFontClass(fontList[i]));
			}
		}

		public function getFontClass(id:String):Class 
		{			
			return _fontsDomain.getDefinition(id) as Class;	
		}

		public function getFont(id:String):Font 
		{
			var fontClass:Class = getFontClass(id);
			return new fontClass as Font;
		}

		/*
		public function getStyleSheet():StyleSheet {
		return _styleSheet;
		}
		 */	
		public static function getInstance():FontManager
		{	
			if (INSTANCE == null) 
			{
				INSTANCE = new FontManager(new SingletonEnforcer());
			}
			
			return INSTANCE;
		}
	}
}

class SingletonEnforcer
{
}